package com.toss.cluster;

import com.toss.common.AddressConstant;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.spi.cluster.zookeeper.ZookeeperClusterManager;

public class ZkNode {
	public static void main(String[] args) {
		Future<Vertx> vertxFuture = Future.future();
		ClusterManager mgr = new ZookeeperClusterManager();
		VertxOptions options = new VertxOptions().setClusterManager(mgr);
		Vertx.clusteredVertx(options, vertxFuture);
		vertxFuture.setHandler(res -> {
			if (res.succeeded()) {
				Vertx vertx = res.result();
				vertx.setPeriodic(1000, event -> {
					vertx.eventBus().publish(AddressConstant.ZK_EVENT_ADDRESS, "Hello");
				});
			} else {
				res.cause().printStackTrace();
			}
		});
	}
}
